package net.skyedu.service.frame;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.skyedu.bean.UserInfo;
import net.skyedu.dao.UserInfoDao;

public class Default extends HttpServlet {

	private static final long serialVersionUID = -7452492747665303419L;

	/**
	 * Constructor of the object.
	 */
	public Default() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		String USERID=request.getParameter("u");
		String sta=request.getParameter("sta");
		int userId=Integer.parseInt(USERID);
		UserInfoDao ud=new UserInfoDao();
		UserInfo user = ud.getSSN1(userId);
//		if(user!=null){
			request.setAttribute("USER", user);
			
			request.setAttribute("usI", userId);
			request.setAttribute("rol", ud.findRoleUser(user.getUserId()));
			request.setAttribute("tips", ud.showTip(userId));
			if(sta.equals("top")){
				request.getRequestDispatcher("attend/frame/top.jsp").forward(request, response);
			}
			if(sta.equals("left")){
				request.getRequestDispatcher("attend/frame/left.jsp").forward(request, response);
			}
			if(sta.equals("right")){
				request.getRequestDispatcher("attend/frame/right.jsp").forward(request, response);
			}
			if(sta.equals("end")){
				request.getRequestDispatcher("attend/frame/end.jsp").forward(request, response);
			}
//		}else{
//			request.getRequestDispatcher("attend/error404.jsp").forward(request, response);
//		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}
}
